//首页分类导航
'use strict';
import React, {Component} from 'react';
import {
    View,
    Text,
    Image,
    TouchableOpacity
} from 'react-native';
import styles from '../style/styles';
import MoreCategory from '../category/Category';//更多分类
import CateList from '../category/Category';

export default class homeCategory extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.showHomeCateList = this.showHomeCateList.bind(this)
        this.state = {};
    }


    redirect(data) {
        let type = data.type
        let isLogin = this.props.isLogin
        if (!isLogin) {
            this.props.toLogin()
            return false;
        }
        let title = data.title
        if (title.indexOf('视频') > -1) {
            this.props.navigation.push('VideoList')
            return false
        }
        if (type == 1) {
            this.props.navigation.push('GoodsIndex',{
                goods_id:data.gid
            })
        } else if (type == 2) {
            this.props.navigation.push('GoodsList',{
                title:data.title,
                cate_id:data.cid
            })
        } else if (type == 4 || type == 5||type == 22) {
            this.props.navigation.push('News')
        } else if (type == 8 || type == 9) {
            this.props.navigator.push({
                component: CateList,
            })
        }else if (type == 19) {
            this.props.navigation.push('ReceiveCenter')
        }

    }


    goMoreCategory() {
        this.props.navigator.push({
            component: MoreCategory
        })
    }


    showHomeCateList() {
        let that = this;
        let dataindex = this.props.dataindex;
        //LOG('dataindex===='+JSON.stringify(dataindex))
        let rows;
        let list = [];
        for (let i in dataindex) {
            rows = (
                <TouchableOpacity style={styles.cate_item} key={i} onPress={() => this.redirect(dataindex[i])}>
                    <Image
                        resizeMode="contain"
                        style={styles.cate_item_img}
                        source={{uri: dataindex[i].nav_logo}}/>
                    <Text style={styles.cate_item_txt}>{dataindex[i].title}</Text>
                </TouchableOpacity>
            )

            list.push(rows)
        }
        return (
            <View style={styles.cate_list}>
                {list}
            </View>);

    }

    render() {
        return (
            <View style={styles.cate_list}>
                {this.showHomeCateList()}
            </View>
        )
    }
}